<?php


namespace App\Models\MainDB;

use Illuminate\Database\Eloquent\Model;

class CrossRoomPkPitContribute extends Model
{
    protected $table = 'ln_cross_room_pk_pit_contribute';

    protected $fillable = [
        'id',                       // 主键id
        'pk_id',         //  跨房间pk_id
        'room_id',         //  房间id
        'pit_user_id',            //  麦位用户user_id
        'value',                    //  贡献总数
        'created_at',
        'update_time',
    ];

    public $timestamps = false;

    /**
     * 新增或更新主播麦位贡献
     * @param $pkId
     * @param $give
     * @param $value
     * @return void
     */
    public function updateContribute($pkId,$give,$value)
    {
        $detail = $this->where('pk_id',$pkId)
            ->where('room_id',$give['room_id'])
            ->where('pit_user_id',$give['gift_user'])
            ->first();
        if (is_null($detail)){
            $insert = [];
            $insert['pk_id'] = $pkId;
            $insert['room_id'] = $give['room_id'];
            $insert['pit_user_id'] = $give['gift_user'];
            $insert['value'] = $value;
            $this->insert($insert);
        }else{
            $this->where('id',$detail->id)->increment('value',$value);
        }
    }

}
